package UI;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;

import controller.DaddySmurfController;
import controller.IMainController;

public class MainWindow extends JFrame{
	private JMenuBar jMenuBar;
	private JScrollPane jTree;
	private JComponent jLogUI;
	private JTabbedPane jEditors;
	private JPanel jButtons;
	
	private IMainController controller;
	/**
	 * 
	 */
	private static final long serialVersionUID = 201204121627L;
	

    /**
     * Creates new form InterfazPrincipal
     */
    public MainWindow() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    private void initComponents() {

        jTree = new ArbolUI();
        jEditors = new EditorsUI();
        jMenuBar = new MenuUI();
        jLogUI = new LogUI();
        jButtons = new ButtonsUI(); 

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("aiXML by PinApel");

        // Create a instance of main controller
        controller = DaddySmurfController.getInstance();
        controller.setView(this);
        
        // Set the menuBar
        this.setJMenuBar(jMenuBar);
        
        //Create the layout and assign it to view 
        BorderLayout mainLayout = new BorderLayout();
        this.setLayout(mainLayout);
       
        // Create the editors and log vies in a dynamic jSplitPane
        JSplitPane componentForEditorsAndLog = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        componentForEditorsAndLog.add(jEditors, JSplitPane.TOP);
        componentForEditorsAndLog.add(jLogUI, JSplitPane.BOTTOM);
        
        // Create the JSplitPane to divide the screen
        JSplitPane jspane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
        jspane.add(jTree, JSplitPane.LEFT);
        jspane.add(componentForEditorsAndLog, JSplitPane.RIGHT);
        
        this.add(jspane, BorderLayout.CENTER);
        this.add(jButtons, BorderLayout.NORTH);
        
        
        // Dimensions Provisional
        jLogUI.setPreferredSize(new Dimension(480,60));
        jEditors.setPreferredSize(new Dimension(480,270));
        jTree.setPreferredSize(new Dimension(132,320));
        componentForEditorsAndLog.setDividerLocation(0.82);
        jspane.setDividerLocation(0.15);
        
        pack();
    }
    
    public MenuUI getMenuBarUI() {
		return (MenuUI) jMenuBar;
	}

	public ArbolUI getTreeUI() {
		return (ArbolUI) jTree;
	}

	public LogUI getLogUI() {
		return (LogUI) jLogUI;
	}

	public EditorsUI getEditorsUI() {
		return (EditorsUI) jEditors;
	}
	
	/**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(InterfazPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(InterfazPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(InterfazPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(InterfazPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainWindow().setVisible(true);
            }
        });
    }

}
